var dataCode;

$(function () {
    var param=$$.getQueryString();
    dataCode=param.dataCode;
    //渲染表格
    var columns = cacheDataList.columnsInit();
    var table = cacheDataList.gridInit(columns);
    //var datas = cacheDataList.dataInit();
    //$("#dataTable").bootstrapTable("append",datas);
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var cacheDataList = {
        columnsInit:function(){
            return  [{
                field: 'od',
                title: '序号',
                width:'2%',
                align:'center',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },{field:"colName",title:"数据名称",align:"center",valign:"middle",sortable:false
                ,formatter:function(value,row,index){
                    var str='';
                    if(row.colName=='lb' ){
                        str='上次采集差值';
                    }
                    if(row.colName=='ls' ){
                        str='上次采集时间差';
                    }
                    if(row.colName=='lo' ){
                        str='上次仪表数值';
                    }if(row.colName=='lt' ){
                        str='上次时间';
                    } else if(row.colName=='dcode'){
                        str='设备编号';

                    }else if(row.colName=='dtype'){
                        str='数据类型';

                    }else if(row.colName=='code'){

                        str='数据编号';
                    }else if(row.colName=='range'){
                        str='仪表量程';

                    }else if(row.colName=='expr'){
                        str='仪表修正公式';

                    }else if(row.colName=='scale'){
                        str='仪表的数据精度';

                    }else if(row.colName=='cycle'){
                        str='采集周期';

                    }else if(row.colName=='yield'){
                        str='单位周期内最大量';

                    }else if(row.colName=='multiple'){
                        str='异常倍数';

                    }else if(row.colName=='lj'){
                        str='仪表是否连续增长';

                    }else if(row.colName=='pk'){
                        str='采集点编码';

                    }else if(row.colName=='lv'){
                        str='上次设备计算值';

                    }else if(row.colName=='lc'){
                        str='上次最大量程次数';
                    }


                    return str;
                }
            },{field:"colName",title:"数据项",align:"center",valign:"middle",sortable:false},{field:"colValue",title:"数据值",align:"left",valign:"middle",sortable:"true",formatter:function(value,row,index){

                var str='';
                var e="";
                if(row.colName=='dtype'){

                    if(row.colValue=='1'){
                        e="水";
                    }else if(row.colValue=='2'){
                        e="电";
                    }else{
                        e="煤气";
                    }
                }else if(row.colName=='lj'){
                    if(row.colValue=='1'){
                        e="累计量";
                    }else{
                        e="瞬时量";
                    }

                }else if(row.colName=='nzero'){
                    if(row.colValue=='1'){
                        e="正常状态";
                    }else{
                        e="手动回零";
                    }

                }else{
                    e=row.colValue;
                }

                return e;
            }  }]
        },
        gridInit:function(columns){
            return $("#dataTable").bootstrapTable({
                method: 'post',
                url:$$.restServerUrl+'/bootstrap/basegrid/IotPointBusiness/tableDataList',
                columns: columns,
                striped: 'true',
                classes: 'table table-hover qxttable',
                contentType: "application/x-www-form-urlencoded",
                pageSize:10,
                sidePagination: "server",
                queryParamsType : "page",
                pageNumber:1,
                undefinedText:'-',
                queryParams: function queryParams(params) {   //设置查询参数
                    var args={};
                    args.dataCode=dataCode;
                    args.page=0; //    params.pageNumber
                    args.pageSize=params.pageSize;     //params.pageSize
                    args.isPage=1;
                    var paramStr=JSON.stringify(args);

                    //alert(params.pageNumber+":"+params.pageSize);
                    var param = {
                        params:paramStr
                    };
                    return param;
                }
            })

        },
        dataInit:function(){
            return  []
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = cacheDataList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return cacheDataList;});
    } else {
        !('plugin' in _global) && (_global.cacheDataList = cacheDataList);
    }
}());